package com.wx.mall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wx.mall.user.entity.Ms;
import com.wx.mall.user.mapper.MsMapper;
import com.wx.mall.user.service.IMsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 会员等级设置表 服务实现类
 * </p>
 *
 * @author j
 * @since 2020-03-18
 */
@Service
public class MsServiceImpl extends ServiceImpl<MsMapper, Ms> implements IMsService {

    @Override
    public int setListById(Ms ms) {
        boolean success=this.updateById(ms);
        List<Ms> list=this.list();
        boolean suceeTwo=false;
        int result;
//        修改其他的默认值关
        if(ms.getMsDefaultMember()==1){
            for (Ms m:list
                 ) {
                if(m.getMsId()!=ms.getMsId()){
                    m.setMsDefaultMember(0);
                    suceeTwo=this.updateById(m);
                }
            }
        };
        if (success==true&&suceeTwo==true){
            result=1;
        }else {
            result=0;
        }
        return result;
    }
}
